package com.ruoyi.web.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.domain.TreeSelect;
import com.ruoyi.web.domain.dto.MonitorAreaDto;
import com.ruoyi.web.domain.vo.MonitorAreaTreeVo;
import com.ruoyi.web.service.IMonitorAreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "监控区域控制层")
@RequestMapping("/monitorArea")
public class MonitorAreaController extends BaseController {

    @Autowired
    private IMonitorAreaService monitorAreaService;

    @PostMapping
    @ApiOperation("新增监控区域")
    public AjaxResult add(@RequestBody MonitorAreaDto dto) {
        return monitorAreaService.add(dto);
    }

    @GetMapping("/tree")
    @ApiOperation("查询监控区域树形列表")
    public AjaxResult getTree(MonitorAreaDto dto) {
        List<MonitorAreaTreeVo> list = monitorAreaService.getTreeVoList(dto);
        List<TreeSelect> treeSelects = monitorAreaService.buildMonitorAreaTreeSelect(list);
        return success(treeSelects);
    }

    /**
     * 废弃
     */
    @GetMapping("/cameraTree")
    @ApiOperation("查询监控区域树形列表（带摄像头）")
    public AjaxResult getCameraTree(MonitorAreaDto dto) {
        List<MonitorAreaTreeVo> list = monitorAreaService.getCameraTreeVoList(dto);
        List<TreeSelect> treeSelects = monitorAreaService.buildMonitorAreaTreeSelect(list);
        return success(treeSelects);
    }

    @PutMapping("/rename")
    @ApiOperation("重命名监控区域")
    public AjaxResult rename(@RequestBody MonitorAreaDto dto) {
        return monitorAreaService.rename(dto);
    }

    @PutMapping("/move")
    @ApiOperation("移动监控区域")
    public AjaxResult move(@RequestBody MonitorAreaDto dto) {
        return monitorAreaService.move(dto);
    }

    @DeleteMapping
    @ApiOperation("删除监控区域")
    public AjaxResult delete(MonitorAreaDto dto) {
        return monitorAreaService.delete(dto);
    }
}
